import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/order/order';


export interface OrderParam {
    orderNo?: string;
    username?: string;
    orderStatus?: number;
    payType?: number;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface OrderResponse {
    id?: number;
    orderNo: string;
    memberId: string;
    username?: string;
    orderStatus: number;
    snapshotAddress?: string;
    payType?: number;
    totalAmount?: string;
    freightAmount?: string;
    promotionAmount?: string;
    pointAmount?: string;
    couponAmount?: string;
    adminDiscountAmount?: string;
    finalPayAmount?: string;
    orderComment?: string;
    paymentTime?: string;
    deliveryTime?: string;
    receiveTime?: string;
    commentTime?: string;
    
    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface OrderSaveCommand {
    id?: number;
    orderNo: string;
    memberId: string;
    username?: string;
    orderStatus?: string;
    snapshotAddress?: string;
    payType?: number;
    totalAmount?: string;
    freightAmount?: string;
    promotionAmount?: string;
    pointAmount?: string;
    couponAmount?: string;
    adminDiscountAmount?: string;
    finalPayAmount?: string;
    orderComment?: string;
    paymentTime?: string;
    deliveryTime?: string;
    receiveTime?: string;
    commentTime?: string;
}

export interface OrderResponseList {
    list: OrderResponse[];
    total: number;
}


// 通过OrderParam参数获取分页列表
export function pageOrder(params: OrderParam) {
    return axios.get<OrderResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取订单信息
export function getOrder(id: number) {
    return axios.get<OrderResponse>(`${BASE_URL}/${id}`);
    
}

export function listOrder(params: OrderParam) {
    return axios.get<OrderResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加订单
export function addOrder(params: OrderSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新订单
export function updateOrder(params: OrderSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除订单
export function deleteOrder(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}
